package com.dropdb.demo.controller.wx;

import com.dropdb.demo.bean.vo.BaseRespVO;
import com.dropdb.demo.service.CatalogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@RequestMapping("wx/catalog")
public class WxCatalogController {
    @Autowired
    CatalogService catalogService;

    @RequestMapping(value = "index", method = RequestMethod.GET)
    public BaseRespVO getIndexOfCatalog() {
        HashMap<String, Object> indexOfCatalog = catalogService.getIndexOfCatalog();
        if (indexOfCatalog == null) return BaseRespVO.error(500, "类别信息不存在");
        return BaseRespVO.ok(indexOfCatalog);
    }

    @RequestMapping(value = "current", method = RequestMethod.GET)
    public BaseRespVO getCurrentCatalog(Integer id) {
        HashMap<String, Object> currentCatalog = catalogService.getCurrentCatalog(id);
        if (currentCatalog == null) return BaseRespVO.error(500, "当前类别不存在");
        return BaseRespVO.ok(currentCatalog);
    }
}
